<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/vue.js"></script>
</head>

<body>
    <div id="app">
        <input type="number" v-model='number1'>
        <select name="a" id="" v-model='number2'>
            <option value="+">+</option>
            <option value="-">-</option>
            <option value="*">*</option>
            <option value="/">/</option>
        </select>
        <input type="number" v-model='number3'>
        <button @click='add'>=</button>
        <input type="text" v-model='result' readonly>
    </div>

    <script>

        const vm = new Vue({
            el: '#app',
            data: {
                number1: '',
                number2: '+',
                number3: '',
                result: ''
            },
            methods: {
                // 输入判断不能为空
                add() {
                    if (!(this.number1 && this.number3)) {
                       return alert('不能为空')
                    }
                    // console.log(this.number2);
                    // 计算
                    const jsStr = `${this.number1} ${this.number2} ${this.number3}`
                    // 输出
                    this.result = eval(jsStr)
                }
            }
        })
    </script>
</body>

</html>